package com.chance.cc.crawler.development.command.meta.keyword.common;

import com.chance.cc.crawler.development.command.meta.keyword.CrawlerDomainKeywordCommand;
import com.chance.cc.crawler.meta.core.bean.crawler.CrawlerDomainKeys;
import org.apache.commons.lang3.StringUtils;

import java.io.*;

/**
 * 公共新增关键词
 */
public class CommonKeyword {
    private static final String path = "E:\\chance_work\\chance-crawler-development\\crawler-scripts-command\\src\\main\\java\\com\\chance\\cc\\crawler\\development\\command\\meta\\keyword\\common\\common_keywords.txt";
    private static final String baidu_path = "E:\\chance_work\\chance-crawler-development\\crawler-scripts-command\\src\\main\\java\\com\\chance\\cc\\crawler\\development\\command\\meta\\keyword\\common\\baidu_keyword.txt";
    private static final String simple_path = "E:\\chance_work\\chance-crawler-development\\crawler-scripts-command\\src\\main\\java\\com\\chance\\cc\\crawler\\development\\command\\meta\\keyword\\common\\bilibili_keyword.txt";
    private static final String douyin_path = "E:\\chance_work\\chance-crawler-development\\crawler-scripts-command\\src\\main\\java\\com\\chance\\cc\\crawler\\development\\command\\meta\\keyword\\common\\douyin_kw.txt";

    private static final String TEST_HOST = "192.168.1.215";
    private static final String PRO_HOST = "192.168.1.217";
    private static final int PORT = 9599;

    private static final String IQIYI = "iqiyi";
    private static final String JIEMIAN = "jiemian";
    private static final String TOUTIAO = "toutiao";
    private static final String YOUKU = "youku";
    private static final String BAIBU = "baidu";
    private static final String BILIBILI = "bilibili";
    private static final String DOU_YIN = "douyin";
    private static final String ACFUN = "acfun";
    private static final String PPTV = "pptv";
    private static final String IASK = "iask";
    private static final String DAHE = "dahe";
    private static final String SOUGOU = "sougou";
    private static final String ZHI_HU = "zhihu";
    private static final String DOUBAN = "douban";
    private static final String CCTV = "cctv";


    private static final String SITE_NIKE = "nike";
    private static final String SITE_SEARCH = "searchKw";
    private static final String SITE_SEARCH_KEYWORD = "search_keyword";
    private static final String SITE_TieBa_Kw = "tieba_keyword";//百度贴吧20210729新加关键词
    private static final String SITE_ZhiDao_Kw = "zhidao_keyword";//百度知道20210729整合关键词
    private static final String SITE_SIMPLE = "simple_simple";//临时采集的关键词
    private static final String SITE_DOU_YIN_ZD = "kw_zd";//抖音周度采集关键词
    private static final String SITE_KW = "kw";//抖音日常采集关键词

    private static final String TYPE_ADD = "add";
    private static final String TYPE_DEL = "del";

    public static void main(String[] args)  {
        String host = TEST_HOST;
        String domain = CCTV;
        String site = SITE_NIKE;
        String type = TYPE_ADD;

        try {
            keywordManage(host,domain,site,path,type);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void keywordManage(String host,String domain,String site,String path,String type) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(new File(path)), "UTF-8"));
        String lineData = null;
        while ((lineData = bufferedReader.readLine()) != null){
            if(StringUtils.isBlank(lineData) || lineData.startsWith("#")){
                continue;
            }
            CrawlerDomainKeywordCommand crawlerDomainKeywordCommand = new CrawlerDomainKeywordCommand(host,PORT);

            CrawlerDomainKeys crawlerDomainKeys = new CrawlerDomainKeys();
            crawlerDomainKeys.setDomain(domain);
            crawlerDomainKeys.setSite(site);
            crawlerDomainKeys.setKeyword(lineData);
            crawlerDomainKeys.setStatus(0);
            if(TYPE_ADD.equals(type)){
                crawlerDomainKeywordCommand.addOrUpdateKeys(crawlerDomainKeys);
            }else if(TYPE_DEL.equals(type)){
                crawlerDomainKeywordCommand.delKeys(crawlerDomainKeys);
            }
            System.out.println(lineData);
        }
    }
}
